package com.ctrip.demo.design.flyweight;

import java.util.HashMap;
import java.util.Map;

public class FlyweightFactory {


    private static Map<String, Flyweight> flyweights = new HashMap<String, Flyweight>();

    public static Flyweight getFlyweight(String key) {
        Flyweight flyweight = flyweights.get(key);
        if (flyweight == null) {
            flyweight = new ConcreteFlyweight(key);
            flyweights.put(key, flyweight);
        } else {
            System.out.println("具体享元" + key + "已经存在，被成功获取！");
        }

        return flyweight;
    }

}
